package main

import "fmt"
import "time"

func main() {
	// 看time.Now()输出的值和类型
	now := time.Now()
	fmt.Printf("now = %v nowtype = %T\n", now, now)

	// 通过now可以获取到年月日，时分秒
	fmt.Printf("年=%v\n", now.Year())
	fmt.Printf("月=%v\n", now.Month())
	fmt.Printf("月=%v\n", int(now.Month()))
	fmt.Println("当前日 =", now.Day())
	fmt.Println("当前时 =", now.Hour())
	fmt.Println("当前分 =", now.Minute())
	fmt.Println("当前秒 =", now.Second())

	// 格式化日期时间
	fmt.Printf("当前年月日 %d-%d-%d %d:%d:%d\n",
		now.Year(), now.Month(), now.Day(),
		now.Hour(), now.Minute(), now.Second())

	dateStr := fmt.Sprintf("当前年月日 %d-%d-%d %d:%d:%d\n", now.Year(), now.Month(), now.Day(),
		now.Hour(), now.Minute(), now.Second())

	fmt.Printf("datestr=%v\n", dateStr)

	fmt.Printf(now.Format("2006/01/02 15:04:05"))
	fmt.Println()
	fmt.Printf(now.Format("2006-01-02"))
	fmt.Println()
	fmt.Printf(now.Format("15:04:05"))
	fmt.Println()
}